<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="650" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="130px" label-position="right">

            <el-form-item label="提货点名称" prop="title">
				<el-input v-model="form.title" clearable></el-input>
			</el-form-item>
			<el-form-item label="地址" prop="address">
				<el-input v-model="form.address" clearable></el-input>
			</el-form-item>
			<el-form-item label="经度" prop="lon">
				<el-input v-model="form.lon" clearable></el-input>
			</el-form-item>
			<el-form-item label="纬度" prop="lat">
				<el-input v-model="form.lat" clearable></el-input>
			</el-form-item>

			<el-form-item label="启用" prop="status">
				<el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
			</el-form-item>
			<div class="map-picker-container">
			  <div id="mapContainer" class="map-container"></div>

			</div>

		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>




	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				MAP_KEY:'I2VBZ-SDXWW-J4CR3-O25UG-55PA5-DFB37',
				users:[],
				is_getuser:0,
				mode: "add",
                cat:[],
				titleMap: {
					add: '新增',
					edit: '编辑',
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					status:'1'
				},
				//验证规则
				rules: {
					title: [
						{required: true, message: '请输入'}
					],
					address: [
						{required: true, message: '请输入'}
					],
					lon: [
						{required: true, message: '请输入'}
					],
					lat: [
						{required: true, message: '请输入'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {

			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						delete this.form.pname;
						this.isSaveing = true;
                        var res = await this.$API.system.universal.handle.post(this.form,'/system/pickup_save');
						this.isSaveing = false;
						if(res.code == 200){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				})
			},
			//表单注入数据
			setData(data){
				this.form = data
			}
		}
	}
</script>

<style>
.chkbox{
    margin-bottom: 10px;
    display: inline-block;
	width: 100%;
}
.ipt{
	width: 300px;
	margin-left:8px
}
</style>
